package utils;

import android.util.Log;
import android.widget.TextView;

import com.example.administrator.test.R;
import com.example.administrator.test.passengernearcar.Constant;
import com.example.administrator.test.passengernearcar.PostRoute;
import com.example.administrator.test.passengernearcar.SendLatLngBean;
import com.example.administrator.test.passengernearcar.SendOrderBean;
import com.example.administrator.test.passengernearcar.TurnNearCarBean;
import com.example.administrator.test.passengernearcar.TurnOrderBean;
import com.google.gson.Gson;

import java.util.List;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.GsonConverterFactory;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2016/12/23.
 */
public class SendOrder {
    public static void sendOrder(final TextView tv_money_special, String token, String locPlaceName, String locPlaceLng, String locPlaceLat, String endPlaceName,
                                 final String endPlaceLng, final String endPlaceLat, String locCarType){
        SendOrderBean sendOrderBean=new SendOrderBean();
        sendOrderBean=initData(sendOrderBean,token,locPlaceName,locPlaceLng,locPlaceLat,endPlaceName,endPlaceLng,endPlaceLat,locCarType);
        Gson gson=new Gson();
        String route=gson.toJson(sendOrderBean);
        Log.i("tag",route+"----------------------------");
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        PostRoute postRoute=retrofit.create(PostRoute.class);
        RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),route);
        Call<TurnOrderBean> call=postRoute.postOrder(body);
        call.enqueue(new Callback<TurnOrderBean>() {
            @Override
            public void onResponse(Call<TurnOrderBean> call, Response<TurnOrderBean> response) {
                TurnOrderBean turnOrderBean=response.body();
                String budget=turnOrderBean.getBudget();
                tv_money_special.setText(budget);
            }

            @Override
            public void onFailure(Call<TurnOrderBean> call, Throwable t) {
                Log.i("tag","出错");

            }
        });
    }
    private static SendOrderBean initData(SendOrderBean sendOrderBean,String token,String locPlaceName, String locPlaceLng,
                                          String locPlaceLat,String endPlaceName, String endPlaceLng,String endPlaceLat,String locCarType){
        sendOrderBean.setOperType("2005");
        sendOrderBean.setToken(token);
        sendOrderBean.setLocPlaceName(locPlaceName);
        sendOrderBean.setLocPlaceLng(locPlaceLng);
        sendOrderBean.setLocPlaceLat(locPlaceLat);
        sendOrderBean.setEndPlaceName(endPlaceName);
        sendOrderBean.setEndPlaceLng(endPlaceLng);
        sendOrderBean.setEndPlaceLat(endPlaceLat);
        sendOrderBean.setLocCarType(locCarType);
        return sendOrderBean ;
    }
}

